<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="链接 异步：现在和将来的时间间隙并行：能够同时发生的事情 并行：比如进程与线程，独立运行并且能同时运行。 123456fun : function()&amp;#123;	func1();	func2();	http1();	http2();&amp;#125; 多进程每个tab标签页有一个独立的进程（有的可能会合并） 比如：  Browser进程：主进程； 第三方插件进程； GPU进程； 浏览器渲染进程。  单">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript之运行机制">
<meta property="og:url" content="http://yoursite.com/2020/12/08/JavaScript之运行机制/index.html">
<meta property="og:site_name" content="春风自是人间客">
<meta property="og:description" content="链接 异步：现在和将来的时间间隙并行：能够同时发生的事情 并行：比如进程与线程，独立运行并且能同时运行。 123456fun : function()&amp;#123;	func1();	func2();	http1();	http2();&amp;#125; 多进程每个tab标签页有一个独立的进程（有的可能会合并） 比如：  Browser进程：主进程； 第三方插件进程； GPU进程； 浏览器渲染进程。  单">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-12-08T13:25:25.756Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript之运行机制">
<meta name="twitter:description" content="链接 异步：现在和将来的时间间隙并行：能够同时发生的事情 并行：比如进程与线程，独立运行并且能同时运行。 123456fun : function()&amp;#123;	func1();	func2();	http1();	http2();&amp;#125; 多进程每个tab标签页有一个独立的进程（有的可能会合并） 比如：  Browser进程：主进程； 第三方插件进程； GPU进程； 浏览器渲染进程。  单">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: "",
      labels: ""
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/12/08/JavaScript之运行机制/">





  <title>JavaScript之运行机制 | 春风自是人间客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">春风自是人间客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">是非成败转头空，青山依旧在，几度夕阳红。</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-program">
          <a href="/categories/program" rel="section">
            
            程序
          </a>
        </li>
      
        
        <li class="menu-item menu-item-reading">
          <a href="/categories/reading" rel="section">
            
            阅读
          </a>
        </li>
      
        
        <li class="menu-item menu-item-idea">
          <a href="/categories/idea" rel="section">
            
            想法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
            关于我
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/12/08/JavaScript之运行机制/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="彭丹丹">
      <meta itemprop="description" content>
      <meta itemprop="image" content="https://upload.jianshu.io/users/upload_avatars/830956/debe5156eed7?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="春风自是人间客">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">JavaScript之运行机制</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-12-08T15:44:34+08:00">
                2020-12-08
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/program/" itemprop="url" rel="index">
                    <span itemprop="name">program</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1,034
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4
                </span>
              
            </div>
          

          
          
        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><a href="https://www.cnblogs.com/cangqinglang/p/8963557.html" target="_blank" rel="noopener">链接</a></p>
<p><strong>异步</strong>：现在和将来的时间间隙<br><strong>并行</strong>：能够同时发生的事情</p>
<p>并行：比如进程与线程，独立运行并且能同时运行。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fun : function()&#123;</span><br><span class="line">	func1();</span><br><span class="line">	func2();</span><br><span class="line">	http1();</span><br><span class="line">	http2();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="多进程"><a href="#多进程" class="headerlink" title="多进程"></a>多进程</h1><p>每个tab标签页有一个独立的进程（有的可能会合并）</p>
<p>比如：</p>
<ul>
<li>Browser进程：主进程；</li>
<li>第三方插件进程；</li>
<li>GPU进程；</li>
<li>浏览器渲染进程。</li>
</ul>
<h1 id="单线程"><a href="#单线程" class="headerlink" title="单线程"></a>单线程</h1><p>浏览器的渲染进程是<code>多个线程</code>的，是多个，这些线程还是一个一个执行完了才执行下一个，所以<code>JS引擎是单线程</code>的。</p>
<p>比如：</p>
<ul>
<li>GUI渲染线程</li>
<li>JS引擎线程</li>
<li>事件触发线程</li>
<li>定时触发器线程</li>
</ul>
<h1 id="浏览器渲染流程"><a href="#浏览器渲染流程" class="headerlink" title="浏览器渲染流程"></a>浏览器渲染流程</h1><p><strong>沉浸树（render树）</strong>：</p>
<ul>
<li>1.处理HTML标签构建DOM树；</li>
<li>2.处理CSS标签构建CSSOM树；</li>
<li>3.DOM和CSSOM树被组合形成渲染树（render树）；</li>
<li>4.布局render树，计算尺寸、位置；</li>
<li>5.绘制render树，绘制页面像素信息；</li>
<li>6.发给图形处理器（GPU），显示在屏幕上。</li>
</ul>
<p><strong>CSS是否会阻塞dom树渲染？</strong></p>
<p>由上面的流程可知，不知阻塞DOM树，但会阻塞CSSOM树。</p>
<h1 id="事件循环（Event-Loop）、宏任务（macrotask）、微任务（microtask）"><a href="#事件循环（Event-Loop）、宏任务（macrotask）、微任务（microtask）" class="headerlink" title="事件循环（Event Loop）、宏任务（macrotask）、微任务（microtask）"></a>事件循环（<code>Event Loop</code>）、宏任务（<code>macrotask</code>）、微任务（<code>microtask</code>）</h1><p>事件循环（<code>Event Loop</code>）：执行完宏任务后，将微任务排队添加任务，执行后再循环检查有没有宏任务……所以整个过程称为事件循环。<br>宏任务（<code>macrotask</code>）：主代码、setTimeout、setInterval、setImmediate(IE)、MessageChannel<br>微任务（<code>microtask</code>）：promise、process.nextTick、MutationObserver</p>
<p>执行顺序：先宏任务–》执行结束后–》再执行所有微任务–》渲染–》下一个宏任务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">console.log(&apos;start&apos;);</span><br><span class="line"></span><br><span class="line">setTimeout(function() &#123;</span><br><span class="line">  console.log(&apos;1&apos;);</span><br><span class="line">&#125;, 10);</span><br><span class="line"></span><br><span class="line">new Promise(resolve =&gt; &#123;</span><br><span class="line">    console.log(&apos;2&apos;);</span><br><span class="line">    resolve();</span><br><span class="line">    setTimeout(() =&gt; console.log(&apos;3&apos;), 10);</span><br><span class="line">&#125;).then(function() &#123;</span><br><span class="line">    console.log(&apos;4&apos;)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">console.log(&apos;end&apos;);</span><br></pre></td></tr></table></figure>
<p>这里的执行顺序就是<code>start--&gt;2--&gt;end--&gt;4--&gt;1--&gt;3</code></p>
<p><strong>注意</strong>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">promise是立即执行的，创建的时候就会执行，不存在将promise推入微任务；</span><br><span class="line">resolve()是表示promise的状态为fullfilled，相当于只是定义了一个有状态的promise，并没有调用它；</span><br><span class="line">promise调用then的前提是promise的状态为fullfilled；</span><br><span class="line">只有promise调用then的时候，then里面的函数才会被推入微任务中。</span><br></pre></td></tr></table></figure>
<h1 id="WebWorker"><a href="#WebWorker" class="headerlink" title="WebWorker"></a>WebWorker</h1><p><strong>用法</strong></p>
<h2 id="不使用时"><a href="#不使用时" class="headerlink" title="不使用时"></a>不使用时</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset=&quot;utf-8&quot;/&gt;</span><br><span class="line">    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=GBK&quot; /&gt;</span><br><span class="line">    &lt;title&gt;计算&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;p&gt;打印1-9999的数：</span><br><span class="line">      &lt;div id=&quot;result&quot;&gt;&lt;/div&gt;&lt;/p&gt;</span><br><span class="line">    &lt;script type=&quot;text/javascript&quot;&gt;</span><br><span class="line">        var n = 0;</span><br><span class="line">        while (n &lt; 9999) </span><br><span class="line">        &#123;</span><br><span class="line">            n += 1;</span><br><span class="line">            document.getElementById(&apos;result&apos;).innerHTML += (n + &quot;, &quot;);</span><br><span class="line">        &#125;</span><br><span class="line">    &lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<h2 id="使用时"><a href="#使用时" class="headerlink" title="使用时"></a>使用时</h2><p>test.html<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html &gt;</span><br><span class="line">  &lt;head&gt;</span><br><span class="line">    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;</span><br><span class="line">    &lt;title&gt;打印1-9999的数&lt;/title&gt;</span><br><span class="line">  &lt;/head&gt;</span><br><span class="line">  &lt;body&gt;</span><br><span class="line">    &lt;div id=&quot;app&quot;&gt;</span><br><span class="line">      打印1-9999的数：</span><br><span class="line">      &lt;div id=&quot;result&quot; style=&quot;width: 1500px; height:auto; border:1px solid red; word-wrap: break-word; &quot;&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">    &lt;script&gt;</span><br><span class="line">      var worker = new Worker(&quot;./woker.js&quot;);</span><br><span class="line">      worker.onmessage = function (event) &#123;</span><br><span class="line">        document.getElementById(&quot;result&quot;).innerHTML += event.data + &quot;,&quot;;</span><br><span class="line">      &#125;;</span><br><span class="line">      worker.postMessage(&apos;data&apos;);</span><br><span class="line">    &lt;/script&gt;</span><br><span class="line">  &lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure></p>
<p>worker.js<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">onmessage = function (event) &#123;</span><br><span class="line">    var n = 1;</span><br><span class="line">    while (n &lt; 9999) &#123;</span><br><span class="line">        n += 1;</span><br><span class="line">        postMessage(n);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><ul>
<li>不使用时页面可能会卡6、7秒</li>
<li>使用后页面立马渲染DOM，下面的值可能还在加载，但上面已经能看到数据了。</li>
</ul>
<p>创建<code>WebWorker</code>时，js引擎向浏览器申请开一个子线程（子线程是浏览器开的，完全受主线程控制，且不能操作DOM，只能把数据发送给主线程后，由主线程操作DOM）；<br>JS引擎是单线程的，本质上还是没有改变。</p>
<h2 id="更多"><a href="#更多" class="headerlink" title="更多"></a>更多</h2><p>如果在本地运行，可能会找不到<code>webworker</code>，</p>
<p><code>Uncaught DOMException: Failed to construct &#39;Worker&#39;</code></p>
<p>可以使用live-server搭建一个简单的本地服务器：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">`npm install live-server -g`</span><br><span class="line">`live-server`</span><br></pre></td></tr></table></figure>
<h1 id="setTimeout相关"><a href="#setTimeout相关" class="headerlink" title="setTimeout相关"></a>setTimeout相关</h1><p>setTimeout并不是由JS引擎计数的，因为单线程会阻塞，会影响计数的准确，因此通过单独线程来计时并触发。<br>setTiemout最小为4，不满会加成4。</p>
<p>setTimeout的时间假设设置为1000，不是说1秒后立马会执行，而是尽快执行，把任务添加到了队列中，如果排到它了，就立马执行。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/12/08/JavaScript之观察者模式(Obverse)/" rel="next" title="JavaScript之观察者模式(Obverse)">
                <i class="fa fa-chevron-left"></i> JavaScript之观察者模式(Obverse)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/12/08/JavaScript之Function函数/" rel="prev" title="JavaScript之Function函数">
                JavaScript之Function函数 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zODk2OC8xNTQ5Ng=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://upload.jianshu.io/users/upload_avatars/830956/debe5156eed7?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240" alt="彭丹丹">
            
              <p class="site-author-name" itemprop="name">彭丹丹</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">183</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#多进程"><span class="nav-number">1.</span> <span class="nav-text">多进程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#单线程"><span class="nav-number">2.</span> <span class="nav-text">单线程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#浏览器渲染流程"><span class="nav-number">3.</span> <span class="nav-text">浏览器渲染流程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#事件循环（Event-Loop）、宏任务（macrotask）、微任务（microtask）"><span class="nav-number">4.</span> <span class="nav-text">事件循环（Event Loop）、宏任务（macrotask）、微任务（microtask）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#WebWorker"><span class="nav-number">5.</span> <span class="nav-text">WebWorker</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#不使用时"><span class="nav-number">5.1.</span> <span class="nav-text">不使用时</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用时"><span class="nav-number">5.2.</span> <span class="nav-text">使用时</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">5.3.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#更多"><span class="nav-number">5.4.</span> <span class="nav-text">更多</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#setTimeout相关"><span class="nav-number">6.</span> <span class="nav-text">setTimeout相关</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">彭丹丹</span>

  
</div>


	<div class="powered-by">
	<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
	  本站访客数:<span id="busuanzi_value_site_uv"></span>
	</span>
	</div>
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

  undefined
  
  <!-- 页面爆炸效果 -->
  
<script src="/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/tororo.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true}});</script></body>
</html>
